package com.lysj.bhp.system.controller;


import com.lysj.bhp.system.base.BaseConst;
import com.lysj.bhp.system.vo.ConfigVo;
import com.lysj.bhp.util.web.ParamUtil;
import com.lysj.bhp.util.web.Resp;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("admin/system_config")
public class SystemConfigController extends BaseConst {
    

    // 基本接口///////////////////////////////////////
    @GetMapping(value = "/list")
    public Resp list() {
        List<ConfigVo> configVos = new ArrayList<>();

        ConfigVo isAllIco = new ConfigVo();
        isAllIco.setKey("isAllIco");
        isAllIco.setName("是否开启全部用户投资");
        isAllIco.setValue(BaseConst.isAllIco ? "已开始" : "未开始");
        configVos.add(isAllIco);

        ConfigVo bitcoinToDollar = new ConfigVo();
        bitcoinToDollar.setKey("bitcoinToDollar");
        bitcoinToDollar.setName("比特币到美元的汇率");
        bitcoinToDollar.setValue(exchangeRate.getBITCOIN_TO_DOLLAR().setScale(6,BigDecimal.ROUND_HALF_UP) + "");
        configVos.add(bitcoinToDollar);

        ConfigVo ethereumToDollar = new ConfigVo();
        ethereumToDollar.setKey("ethereumToDollar");
        ethereumToDollar.setName("以太币到美元的汇率");
        ethereumToDollar.setValue(exchangeRate.getETHEREUM_TO_DOLLAR().setScale(6,BigDecimal.ROUND_HALF_UP) + "");
        configVos.add(ethereumToDollar);

        ConfigVo bhpcToDollar = new ConfigVo();
        bhpcToDollar.setKey("bhpcToDollar");
        bhpcToDollar.setName("算力币到美元的汇率");
        bhpcToDollar.setValue(exchangeRate.getBHPC_TO_DOLLAR().setScale(6,BigDecimal.ROUND_HALF_UP)  + "");
        configVos.add(bhpcToDollar);

        ConfigVo icoProcess = new ConfigVo();
        icoProcess.setKey("icoProcess");
        icoProcess.setName("ICO进度控制");
        icoProcess.setValue(BaseConst.ICO_PROCESS);
        configVos.add(icoProcess);

        ConfigVo accountNumber = new ConfigVo();
        accountNumber.setKey("transferContant");
        accountNumber.setName("转账联系人");
        accountNumber.setValue(BaseConst.TRANSFER_CONTANT);
        configVos.add(accountNumber);

        ConfigVo accountAddress = new ConfigVo();
        accountAddress.setKey("transferWechat");
        accountAddress.setName("转账微信号");
        accountAddress.setValue(BaseConst.TRANSFER_WECHAT);
        configVos.add(accountAddress);

        return new Resp(configVos);
    }

    @PostMapping(value = "/reserve_ico")
    public Resp reserveIco(String key) {
        if (ParamUtil.isBlack(key)) {
            return new Resp(Resp.PARAM_ERROR, "key不能为空");
        }
            if (BaseConst.isAllIco) {
                BaseConst.isAllIco = false;
            } else {
                BaseConst.isAllIco = true;
            }
        return new Resp("设置成功");
    }

    @PostMapping(value = "/set_bhpc_to_dollar")
    public Resp setBhpcToDollar(Double bhpcToDollar) {
        if (bhpcToDollar == null || bhpcToDollar == 0) {
            return new Resp(Resp.PARAM_ERROR, "请输入算力币到美元的汇率");
        }
        exchangeRate.setBHPC_TO_DOLLAR(new BigDecimal(bhpcToDollar));
        return new Resp("设置成功");
    }

    @PostMapping(value = "/set_ico_process")
    public Resp setIcoProcess(String process) {
        if (ParamUtil.isBlack(process)) {
            return new Resp(Resp.PARAM_ERROR, "请输入三个数字中间用-隔开");
        }
        BaseConst.ICO_PROCESS = process;
        return new Resp("设置成功");
    }

    @PostMapping(value = "/set_account_number")
    public Resp setAccountNumber(String accountNumber) {
        if (accountNumber == null || accountNumber == "") {
            return new Resp(Resp.PARAM_ERROR, "请输入转账联系人");
        }
        BaseConst.TRANSFER_CONTANT = accountNumber;
        return new Resp("设置成功");
    }

    @PostMapping(value = "/set_account_address")
    public Resp setAccountAddress(String accountAddress) {
        if (accountAddress == null || accountAddress == "") {
            return new Resp(Resp.PARAM_ERROR, "请输入转账微信号");
        }
        BaseConst.TRANSFER_WECHAT = accountAddress;
        return new Resp("设置成功");
    }

}
